<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	    <table style="width:auto;">
	        <tr>
	            <td>
					<a class="mini-button" iconCls="icon-add" onclick="onAddDept('添加部门')">增加部门</a>
					<a class="mini-button" iconCls="icon-edit" onclick="onEditDept('编辑名称')">编辑</a>
					<a class="mini-button" iconCls="icon-remove" onclick="onRemoveDept()">删除</a>
	            </td>
	        </tr>
	    </table>           
	</div>
	<div class="mini-fit" >
    <div id="datagrid1" class="mini-datagrid " idField="id" pageSize="20"
		url="dept_list_view.do" 
		style="width:100%;height:100%;" allowCellSelect="true" multiSelect="true">
		<div property="columns">
			<div type="indexcolumn" headerAlign="center">#</div>
			<div field="name" width="100" headerAlign="center" renderer="onActionRenderer" align="center">名称</div>
			<div field="description" width="100" headerAlign="center" align="center">说明</div>
			<div field="createTime" width="100" headerAlign="center" align="center">创建时间</div>
			<div field="updateTime" width="100" headerAlign="center" align="center">修改时间</div>
		</div>
	</div>
	</div>
<script type="text/javascript">
	mini.parse();
	var grid = mini.get("datagrid1");
	grid.reload();
	
	function onAddDept(title) {
	    mini.open({
	   		url: "medical_dept_add.do",
	   		allowResize:false,
           	title: title, width: 275, height: 280,
           	onload: function () {
               var iframe = this.getIFrameEl();
               var data = { action:"new" };
               iframe.contentWindow.SetData(data);
       		},
    	   	ondestroy: function (action) {
    	   		if(action == 'succ'){
    	   			mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "保存成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
    	   			grid.reload();
    	   		}
            }
     	});
	}
		
	function onEditDept(title) {
		var row = grid.getSelected();
	    if(row){
    		mini.open({
    	   		url: "medical_dept_edit.do",
    	   		allowResize:false,
               	title: title, width: 275, height: 280,
               	onload: function () {
                   var iframe = this.getIFrameEl();
                   var data = { row: row };
                   iframe.contentWindow.SetData(data);
          		},
	    	   	ondestroy: function (action) {
	    	   		if(action == 'succ'){
	    	   			mini.showMessageBox({
		                    title: "提示",
		                    showModal:false,
		                    iconCls: "mini-messagebox-info",
		                    message: "修改成功！",
		                    timeout: 3000,
		                    x: 'right',
		                    y: 'bottom'
		                });
		    	   		grid.load();
	    	   		}
                }
         	});
	    }else{
	    	mini.alert("请选择一个部门");
	    }
	}
	
	function onRemoveDept(e) {
		var row = grid.getSelected();
	    if (row) {
   			mini.confirm("确定删除记录？", "确定？",
        	function (action) {
           		if (action == "ok") {
					$.post('dept_includes_user.do', {id: row.id}, function(data){
						if(data.result == 'error'){
							mini.alert("数据错误，类别id不能为空");
						} else if(data.result == 'true'){
							mini.alert("当前部门下有用户，无法删除！");
						}else{
    						$.post('medical_dept_del.do', {id: row.id}, function(data){
	   	    					if(data.success){
		   	    					mini.showMessageBox({
					                    title: "提示",
					                    showModal:false,
					                    iconCls: "mini-messagebox-info",
					                    message: "删除成功！",
					                    timeout: 3000,
					                    x: 'right',
					                    y: 'bottom',
					                });
	   	    						grid.load();
	   	    					}else{
	   	    						mini.alert("id不能为空，删除失败！");
	   	    					}
   	    					}, "json");
						}
					}, "json");
   				}
   			});
	    }else{
	    	mini.alert("请选择一个部门");
	    }
	}

</script>
</body>
</html>